/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package paquetevistas.compra;

import controlador.almacen.controladoralmacen;
import controlador.compra.controladorcompra;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import modelos.Compra;
import modelos.Detallecompra;
import modelos.Productoxproveedor;
import modelos.Proveedor;
import modelos.Requerimientocompraxproducto;
import modelos.RequerimientocompraxproductoId;

/**
 *
 * @author Jacklin
 */
public class ProductosCompra extends javax.swing.JInternalFrame {

     ProductsxPurchaseTableModel myProductsxPurchaseTableModel = new ProductsxPurchaseTableModel();
     public static controladoralmacen mycontroladoralmacen = new controladoralmacen();
     public static controladorcompra mycontroladorcompra = new controladorcompra();
    /**
     * Creates new form ProductosCompra
     */
    
    class ProductsxPurchaseTableModel extends AbstractTableModel {
        List<Detallecompra> prodsxcomp = new ArrayList<Detallecompra>();
        
        public ProductsxPurchaseTableModel() {
            prodsxcomp = lbj.LBJ.Login.escritorio.compra.detallexcomp;
        }
        String[] titles = {"N° de requerimiento","Producto", "Cantidad", "Precio (S/.)"};

        public int getRowCount() {
            return prodsxcomp.size();
        }

        public int getColumnCount() {
            return 4;
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            String res = null;
            Detallecompra prodsxcomp2 = prodsxcomp.get(rowIndex);
            RequerimientocompraxproductoId requerimientocompxprodId=prodsxcomp2.getRequerimientocompraxproducto().getId();
            Requerimientocompraxproducto requerimientocompxprod=prodsxcomp2.getRequerimientocompraxproducto();
            int idprod=requerimientocompxprodId.getIdproducto();
            int idcomp =prodsxcomp2.getCompra().getIdcompra();
            Proveedor proveedor=mycontroladorcompra.sacaproveedorbyidcomp(idcomp);
            int idprov = proveedor.getIdproveedor();
//            Productoxproveedor prodsxprov= mycontroladorcompra.sacaproductoxproveedor(idprov, idprod);
            
            switch (columnIndex) {
                case 0:
                    res = "" + requerimientocompxprod.getId().getIdreqerimientocompra();
                    break;
                case 1:
                    res= ""+mycontroladoralmacen.sacaproductobyid(idprod).getNombre();
                    break;
                case 2:
                    res = "" + prodsxcomp2.getCantidad();
                    break;
                case 3:
//                    res=""+ prodsxprov.getPrecio();
                    res=""+ prodsxcomp2.getPrecio();
                    break;
            }
            return res;
        }
        
        public String getColumnName(int col) {
            return titles[col];
        }
        
    }
    
    public ProductosCompra() {
        initComponents();
        loadComponents();
        jTable1.setModel(myProductsxPurchaseTableModel);
        refreshProductsxPurchaseTable();
    }

    void loadComponents(){      
        Compra compra2 = lbj.LBJ.Login.escritorio.compra.compradetalle;
         int idcomp=compra2.getIdcompra();
//         Proveedor proveedor=mycontroladorcompra.sacaproveedorbyidcomp(idcomp);
         String razon=mycontroladorcompra.sacarazonbyidcomp(idcomp);
         
        jidcompra.setText(""+compra2.getIdcompra());
        jmonto.setText(""+compra2.getPrecioacordado());
        jproveedor.setText(razon);
    }
    
    void refreshProductsxPurchaseTable() {
        myProductsxPurchaseTableModel.prodsxcomp = lbj.LBJ.Login.escritorio.compra.detallexcomp;
        myProductsxPurchaseTableModel.fireTableChanged(null);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jidcompra = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jproveedor = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jmonto = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setTitle("Detalle de Compra");

        jLabel1.setText("Código de la compra:");

        jidcompra.setEditable(false);

        jLabel2.setText("Nombre del proveedor:");

        jproveedor.setEditable(false);

        jLabel3.setText("Monto Total:");

        jmonto.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jidcompra)
                    .addComponent(jproveedor)
                    .addComponent(jmonto, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE))
                .addGap(19, 19, 19))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jidcompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jproveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jmonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "N° de requerimiento", "Producto", "Cantidad", "Precio de producto (S/.)"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jScrollPane1)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(80, 80, 80))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jidcompra;
    private javax.swing.JTextField jmonto;
    private javax.swing.JTextField jproveedor;
    // End of variables declaration//GEN-END:variables
}
